package Szadoban;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

import javax.swing.*;

/** Menu window */

public class Menu extends MainFrame implements ActionListener {
	public static ArrayList<Users> UserList = new ArrayList<Users>();
	public JPanel c1;// menupanel1
	public JPanel c2;// menupanel2
	public JPanel scorepanel;// main scorepanel
	public JPanel helppanel;// helpanel
	JButton play;
	JButton butscores;
	JButton help;
	JButton quit;
	JButton undo;
	JLabel text;
	JPanel bPanel;
	JLabel scoretitle;
	JLabel[] scores;// array with scores
	JPanel panelabel;
	JButton signup;
	JButton login;
	LoginFrame lframe;
	SignUpFrame sframe;
	GameWindow gamewindow;

	// ImagePanel a;
	/**
	 * Class constructor, creates menu structure
	 */
	public Menu() {

		// a=new ImagePanel("tlo.png");
		// a.setBounds(0,0,400,400);
		// a.setOpaque(false);

		// UserList.add(new Users("Szadekk",3020));
		SetMainMenu();
		this.setContentPane(c1);
		SetSecondMenu();
		SetScoreFrame();
		SetHelpFrame();

		this.setVisible(true);

	}

	/**
	 * Method creates panel with main menu structure
	 */
	public void SetMainMenu() {
		c1 = new JPanel();
		c1.setLayout(new BoxLayout(c1, BoxLayout.Y_AXIS));
		text = new JLabel("Sokoban");
		play = new JButton("Play");
		butscores = new JButton("Scores");
		help = new JButton("Help");
		quit = new JButton("Quit");
		bPanel = new JPanel();
		bPanel.setSize(400, 400);
		bPanel.setLayout(new BoxLayout(bPanel, BoxLayout.Y_AXIS));

		text.setAlignmentX(Component.CENTER_ALIGNMENT);
		play.setAlignmentX(Component.CENTER_ALIGNMENT);
		butscores.setAlignmentX(Component.CENTER_ALIGNMENT);
		help.setAlignmentX(Component.CENTER_ALIGNMENT);
		quit.setAlignmentX(Component.CENTER_ALIGNMENT);

		c1.add(text);
		c1.add(bPanel);
		bPanel.add(javax.swing.Box.createRigidArea(new Dimension(0, 30)));
		bPanel.add(play);
		bPanel.add(javax.swing.Box.createRigidArea(new Dimension(0, 30)));
		bPanel.add(butscores);
		bPanel.add(javax.swing.Box.createRigidArea(new Dimension(0, 30)));
		bPanel.add(help);
		bPanel.add(javax.swing.Box.createRigidArea(new Dimension(0, 30)));
		bPanel.add(quit);

		play.addActionListener(this);
		butscores.addActionListener(this);
		help.addActionListener(this);
		quit.addActionListener(this);
	}

	/**
	 * Method creates panel with second menu structure
	 */

	public void SetSecondMenu() {
		c2 = new JPanel();
		c2.setLayout(new BoxLayout(c2, BoxLayout.PAGE_AXIS));
		login = new JButton("Login");
		signup = new JButton("Sign Up");
		undo = new JButton("Undo");

		login.setAlignmentX(Component.CENTER_ALIGNMENT);
		signup.setAlignmentX(Component.CENTER_ALIGNMENT);
		login.setAlignmentY(Component.CENTER_ALIGNMENT);
		signup.setAlignmentY(Component.CENTER_ALIGNMENT);
		undo.setAlignmentY(Component.CENTER_ALIGNMENT);
		undo.setAlignmentX(Component.CENTER_ALIGNMENT);

		text.setFont(new Font("Jokerman", Font.PLAIN, 80));

		c2.add(javax.swing.Box.createRigidArea(new Dimension(0, 36)));
		c2.add(login);
		c2.add(javax.swing.Box.createRigidArea(new Dimension(0, 30)));
		c2.add(signup);
		c2.add(javax.swing.Box.createRigidArea(new Dimension(0, 30)));
		c2.add(undo);

		login.addActionListener(this);
		signup.addActionListener(this);
		undo.addActionListener(this);
	}

	/**
	 * Method creates frame with table of scores
	 */

	public void SetScoreFrame() {
		scorepanel = new JPanel();
		panelabel = new JPanel();
		panelabel.setLayout(new GridLayout(5, 2));
		scoretitle = new JLabel("Best scores:");
		// for (int i = 0; i < UserList.size(); i++) {
		// scores = new JLabel[10];
		// scores[i] = new JLabel("user");// UserList.get(i).name);// +
		// UserList.get(i).score );
		// }
		scoretitle.setFont(new Font("Jokerman", Font.PLAIN, 80));
		scorepanel.add(scoretitle, BorderLayout.NORTH);
		scorepanel.add(panelabel, BorderLayout.CENTER);
		scorepanel.add(undo, BorderLayout.SOUTH);

		// for (int i = 0; i < UserList.size(); i++) {
		// panelabel.add(scores[i]);
		// }

	}

	/**
	 * Method creates frame with help and info about game
	 */

	public void SetHelpFrame() {
	}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		Object source = e.getSource();

		if (source == play) {
			this.remove(c1);
			this.setContentPane(c2);
			this.validate();
			this.repaint();
		}

		if (source == butscores) {

			this.remove(c1);
			this.setContentPane(scorepanel);
			this.validate();
			this.repaint();
		}

		if (source == undo) {

			this.remove(c2);
			this.setContentPane(c1);
			this.validate();
			this.repaint();
		}

		if (source == help) {

		}

		if (source == quit) {
			this.dispose();
		}

		if (source == login) {
			this.dispose();
			LoginFrame lframe = new LoginFrame();
		}

		if (source == signup) {
			this.dispose();
			SignUpFrame sframe = new SignUpFrame();

		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Menu menu = new Menu();
	}

}
